#include "touch.h"

uint8_t touch_res = 0;
uint8_t touch3_state = 0;
enum 
{
    PAD_NONE = 0,
    PAD_PUSH,
    PAD_RELEASE
}TOUCH_STATE;

/*20ms period*/
void touchScan(void)
{
    static uint8_t key_delay_cnt = 0, cnt = 0;

    switch (touch3_state)
    {
    case PAD_NONE:
        if(touchRead(PAD3) < 84)
        {
            cnt = 0;
            key_delay_cnt ++;
            if(key_delay_cnt >= 3)
            {
                key_delay_cnt = 0;
                touch3_state ++;
            }
        }
    break;
    case PAD_PUSH:
        if(touchRead(PAD3) >= 84)
        {
            cnt = 0;
            key_delay_cnt ++;
            if(key_delay_cnt >= 3)
            {
                key_delay_cnt = 0;
                touch3_state ++;
            }
        }
    break;
    case PAD_RELEASE:
        touch3_state = PAD_NONE;
        touch_res = TOUCH3_PUSH;
        Serial.println("key3 push");
    break;
    default:
        break;
    }
    cnt++;
    if(cnt >= 50)
    {
        cnt = 0;
        key_delay_cnt = 0;
        if(touch3_state != PAD_PUSH)
            touch3_state = PAD_NONE;
    }
}

